package edu.ynu.se.xiecheng.achitectureclass.controller;


import edu.ynu.se.xiecheng.achitectureclass.common.controller.LogicController;
import edu.ynu.se.xiecheng.achitectureclass.domain.Result;
import edu.ynu.se.xiecheng.achitectureclass.dao.ShopDao;
import edu.ynu.se.xiecheng.achitectureclass.domain.entity.Shop;
import edu.ynu.se.xiecheng.achitectureclass.domain.dto.AddItemDto;
import edu.ynu.se.xiecheng.achitectureclass.service.ShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;

@Api(tags = "商店控制器")
@RestController
@RequestMapping("/shop")
public class ShopController extends LogicController<ShopService, ShopDao, Shop,Long> {

    public ShopController(ShopService ls) {
        super(ls);
    }

    @PostMapping("/addItem")
    @ApiOperation("新增商品")
    public Result addShop(@RequestBody AddItemDto param){
        return getService().addItem(param.getShopId(),param.getItem());
    }

    @PutMapping("/saleItem")
    @ApiOperation("上架商品")
    public Result saleItem(Long shopId, Long itemId){
        return getService().saleItem(shopId,itemId);
    }

    @PutMapping("/stopSale")
    @ApiOperation("下架商品")
    public Result stopSale(Long shopId, Long itemId){
        return getService().stopSale(shopId,itemId);
    }

    @GetMapping("/getAllShop")
    @ApiOperation("获得所有商店（分页）")
    public Result getAllShop(int page , int size){
        return getService().getAllShop(page,size);
    }

    @GetMapping("/getShopByBusinessId")
    @ApiOperation("根据商家id查商店")
    public Result getShopByBusId(int page , int size , Long businessId){
        return getService().getShopByBusinessId(page,size,businessId);
    }

    @GetMapping("/getShopItemState0")
    @ApiOperation("查询所有未上架商品")
    public Result getShopItemState0(@RequestParam("shopId") Long shopId){
        return getService().getAllLineItemByShopIdState0(shopId);
    }

    @GetMapping("/getShopItemState1")
    @ApiOperation("查询所有上架商品")
    public Result getShopItemState1(@RequestParam("shopId") Long shopId){
        System.out.println("商家ID：");
        System.out.println(shopId);
        return getService().getAllLineItemByShopIdState1(shopId);
    }


    @PutMapping("/acceptOrder")
    @ApiOperation("商店接受订单")
    public Result acceptOrder(Long orderId){
        return  getService().acceptOrder(orderId);
    }

    @PutMapping("/refuseOrder")
    @ApiOperation("商店拒绝订单")
    public Result refuseOrder(Long orderId){
        return  getService().refuseOrder(orderId);
    }

    @GetMapping("/getAllOrderState1")
    @ApiOperation("根据id查完成的订单")
    public Result getAllOrderState1(Long shopId){
        return getService().getAllOrderState2(shopId,1,1);
    }

    @GetMapping("/getAllOrderState2")
    @ApiOperation("根据id查退款的订单")
    public Result getAllOrderState2(Long shopId){
        return getService().getAllOrderState2(shopId,2,1);
    }

    @GetMapping("/getAllOrder")
    @ApiOperation("根据id查所有订单")
    public Result getAllOrder(Long shopId){
        return getService().getAllOrder(shopId);
    }

    @GetMapping("/getAllOrderState0")
    @ApiOperation("查看所有未操作订单")
    public Result getAllOrderState0(Long shopId){
        return getService().getAllOrderState2(shopId,0,1);
    }
}
